home *** CD-ROM | disk | FTP | other *** search
/ LiquidLibrary 2005 February / LiquidLibrary 2005 February - Disc 1.iso / pc / Portfolio Browser / Filters / PDF / LIB / gs_init.ps < prev    next >
Text File  |  2003-01-03  |  60KB  |  1,834 lines

  1. %    Copyright (C) 1989, 2000 Aladdin Enterprises.  All rights reserved.
  2. % This software is licensed to a single customer by Artifex Software Inc.
  3. % under the terms of a specific OEM agreement.
  4.  
  5. % $RCSfile$ $Revision$
  6. % Initialization file for the interpreter.
  7. % When this is run, systemdict is still writable.
  8.  
  9. % Comment lines of the form
  10. %    %% Replace <n> <file(s)>
  11. % indicate places where the next <n> lines should be replaced by
  12. % the contents of <file(s)>, when creating a single merged init file.
  13.  
  14. % The interpreter can call out to PostScript code.  All procedures
  15. % called in this way, and no other procedures defined in these
  16. % initialization files, have names that begin with %, e.g.,
  17. % (%Type1BuildChar) cvn.
  18.  
  19. % Check the interpreter revision.  NOTE: the interpreter code requires
  20. % that the first non-comment token in this file be an integer.
  21. 703
  22. dup revision ne
  23.  { (gs: Interpreter revision \() print revision 10 string cvs print
  24.    (\) does not match gs_init.ps revision \() print 10 string cvs print
  25.    (\).\n) print flush null 1 .quit
  26.  }
  27. if pop
  28.  
  29. % Acquire userdict, and set its length if necessary.
  30. /userdict where
  31.  { pop userdict maxlength 0 eq }
  32.  { true }
  33. ifelse
  34. systemdict exch
  35.  {        % userdict wasn't already set up by iinit.c.
  36.    dup /userdict
  37.    currentdict dup 200 .setmaxlength        % userdict
  38.    .forceput            % userdict is local, systemdict is global
  39.  }
  40. if begin
  41.  
  42. % Define dummy local/global operators if needed.
  43. systemdict /.setglobal known
  44.  { true .setglobal
  45.  }
  46.  { /.setglobal { pop } bind def
  47.    /.currentglobal { false } bind def
  48.    /.gcheck { pop false } bind def
  49.  }
  50. ifelse
  51.  
  52. % Define .languagelevel if needed.
  53. systemdict /.languagelevel known not { /.languagelevel 1 def } if
  54.  
  55. % Optionally choose a default paper size other than U.S. letter.
  56. % (a4) /PAPERSIZE where { pop pop } { /PAPERSIZE exch def } ifelse
  57.  
  58. % Turn on array packing for the rest of initialization.
  59. true setpacking
  60.  
  61. % Define the old MS-DOS EOF character as a no-op.
  62. % This is a hack to get around the absurd habit of MS-DOS editors
  63. % of adding an EOF character at the end of the file.
  64. <1a> cvn { } def
  65.  
  66. % Acquire the debugging flags.
  67. currentdict /DEBUG known   /DEBUG exch def
  68.   /VMDEBUG
  69.     DEBUG {{print mark
  70.             systemdict /level2dict known
  71.          { .currentglobal dup false .setglobal vmstatus
  72.            true .setglobal vmstatus 3 -1 roll pop
  73.            6 -2 roll pop .setglobal
  74.          }
  75.          { vmstatus 3 -1 roll pop
  76.          }
  77.         ifelse usertime 16#fffff and counttomark
  78.           { ( ) print (           ) cvs print }
  79.         repeat pop
  80.         ( ) print systemdict length (    ) cvs print
  81.         ( ) print countdictstack (  ) cvs print
  82.         ( <) print count (    ) cvs print (>\n) print flush
  83.       }}
  84.       {{pop
  85.       }}
  86.      ifelse
  87.   def
  88.  
  89. currentdict /BATCH known   /BATCH exch def
  90. currentdict /DELAYBIND known   /DELAYBIND exch def
  91. currentdict /DISKFONTS known   /DISKFONTS exch def
  92. currentdict /DOINTERPOLATE .knownget { /INTERPOLATE exch def } if
  93. currentdict /ESTACKPRINT known   /ESTACKPRINT exch def
  94. currentdict /FAKEFONTS known   /FAKEFONTS exch def
  95. currentdict /FIXEDMEDIA known   /FIXEDMEDIA exch def
  96. currentdict /FIXEDRESOLUTION known   /FIXEDRESOLUTION exch def
  97. currentdict /LOCALFONTS known   /LOCALFONTS exch def
  98. currentdict /NOBIND known   /NOBIND exch def
  99. /.bind /bind load def
  100. NOBIND { /bind { } def } if
  101. currentdict /NOCACHE known   /NOCACHE exch def
  102. currentdict /NOCCFONTS known   /NOCCFONTS exch def
  103. currentdict /NOCIE known   /NOCIE exch def
  104. currentdict /NODISPLAY known   not /DISPLAYING exch def
  105. currentdict /NOFONTMAP known   /NOFONTMAP exch def
  106. currentdict /NOFONTPATH known   /NOFONTPATH exch def
  107. currentdict /NOGC known   /NOGC exch def
  108. currentdict /NOINTERPOLATE .knownget { /INTERPOLATE exch not def } if
  109. currentdict /NOPAGEPROMPT known   /NOPAGEPROMPT exch def
  110. currentdict /NOPAUSE known   /NOPAUSE exch def
  111. currentdict /NOPLATFONTS known   /NOPLATFONTS exch def
  112. currentdict /NOPROMPT known   /NOPROMPT exch def
  113. % The default value of ORIENT1 is true, not false.
  114. currentdict /ORIENT1 known not { /ORIENT1 true def } if
  115. currentdict /OSTACKPRINT known   /OSTACKPRINT exch def
  116. currentdict /OUTPUTFILE known    % obsolete
  117.  { /OutputFile /OUTPUTFILE load def
  118.    currentdict /OUTPUTFILE .undef
  119.  } if
  120. currentdict /QUIET known   /QUIET exch def
  121. currentdict /SAFER known   /SAFER exch def
  122. currentdict /DELAYSAFER known   /DELAYSAFER exch def
  123. currentdict /SHORTERRORS known   /SHORTERRORS exch def
  124. currentdict /STRICT known   /STRICT exch def
  125. currentdict /TTYPAUSE known   /TTYPAUSE exch def
  126. currentdict /WRITESYSTEMDICT known   /WRITESYSTEMDICT exch def
  127.  
  128. % Acquire environment variables.
  129. currentdict /DEVICE known not
  130.  { (GS_DEVICE) getenv { /DEVICE exch def } if } if
  131.  
  132. (START) VMDEBUG
  133.  
  134. % Open the standard files, so they will be open at the outermost save level.
  135. (%stdin) (r) file pop
  136. (%stdout) (w) file pop
  137. (%stderr) (w) file pop
  138.  
  139. /.currentuserparams where {
  140.   pop mark
  141.     % The Adobe implementations appear to have very large maximum
  142.     % stack sizes.  This turns out to actually make a difference,
  143.     % since some badly-behaved files include extremely long procedures,
  144.     % or construct huge arrays on the operand stack.
  145.     % We reset the stack sizes now so that we don't have to worry
  146.     % about overflowing the (rather small) built-in stack sizes
  147.     % during initialization.
  148.   /MaxDictStack 500
  149.   /MaxExecStack 5000
  150.   /MaxOpStack 50000
  151.   .dicttomark .setuserparams
  152. } if
  153.  
  154. % Define a procedure for skipping over an unneeded section of code.
  155. % This avoids allocating space for the skipped procedures.
  156. % We can't use readline, because that imposes a line length limit.
  157. /.skipeof    % <string> .skipeof -
  158.  { currentfile exch 1 exch .subfiledecode flushfile
  159.  } .bind def
  160.  
  161. % Define procedures to assist users who don't read the documentation.
  162. userdict begin
  163. /help
  164.  { (Enter PostScript commands.  '(filename) run' runs a file, 'quit' exits.\n)
  165.    print flush
  166.  } .bind def
  167. end
  168.  
  169. % Define =string, which is used by some PostScript programs even though
  170. % it isn't documented anywhere.
  171. % Put it in userdict so that each context can have its own copy.
  172. userdict /=string 256 string put
  173.  
  174. % Print the greeting.
  175.  
  176. /printgreeting
  177.  { mark
  178.    product (Ghostscript) search
  179.     { pop pop pop
  180.       (This software comes with NO WARRANTY: see the file PUBLIC for details.\n)
  181.     }
  182.     { pop
  183.     }
  184.    ifelse
  185.    (\n) copyright
  186.    (\)\n) revisiondate 10 mod revisiondate 10 idiv 10 mod (-)
  187.    revisiondate 100 idiv 10 mod revisiondate 1000 idiv 10 mod (-)
  188.    revisiondate 10000 idiv ( \()
  189.    revision 10 mod
  190.    revision 100 mod 10 idiv (.)
  191.    revision 100 idiv ( )
  192.    product
  193.    counttomark
  194.     { (%stdout) (w) file exch 0 .writecvp
  195.     } repeat pop
  196.  } .bind def
  197.  
  198. QUIET not { printgreeting flush } if
  199.  
  200. % Define a special version of def for making operator procedures.
  201. /obind {    % <name> <proc> obind <name> <oper>
  202.   1 index exch .makeoperator
  203. } .bind def
  204. /odef {        % <name> <proc> odef -
  205.   1 index exch .makeoperator def
  206. } .bind def
  207.  
  208. % Define a special version of def for storing local objects into global
  209. % dictionaries.  Like .forceput, this exists only during initialization.
  210. /.forcedef {        % <key> <value> .forcedef -
  211.   currentdict 3 1 roll .forceput
  212. } .bind odef
  213.  
  214. % Define procedures for accessing variables in systemdict and userdict
  215. % regardless of the contents of the dictionary stack.
  216. /.systemvar {        % <name> .systemvar <value>
  217.   //systemdict exch get
  218. } .bind odef
  219. /.userdict {        % - .userdict <dict>
  220.   /userdict .systemvar
  221. } .bind odef
  222. /.uservar {        % <name> .uservar <value>
  223.   .userdict exch get
  224. } .bind odef
  225.  
  226. % If we're delaying binding, remember everything that needs to be bound later.
  227. DELAYBIND NOBIND not and
  228.  { .currentglobal false .setglobal
  229.    systemdict /.delaybind 1500 array .forceput
  230.    .setglobal
  231.    userdict /.delaycount 0 put
  232.     % When we've done the delayed bind, we want to stop saving.
  233.     % Detect this by the disappearance of .delaybind.
  234.    /bind
  235.     { /.delaybind .systemvar dup length 0 ne
  236.        { .delaycount 2 index put
  237.          .userdict /.delaycount .delaycount 1 add put
  238.        }
  239.        { pop .bind
  240.        }
  241.       ifelse
  242.     } .bind def
  243.  } if
  244.  
  245. %**************** BACKWARD COMPATIBILITY
  246. /hwsizedict mark /HWSize null .dicttomark readonly def
  247. /copyscanlines {        % <device> <y> <string> copyscanlines <substr>
  248.   0 3 1 roll 3 index //hwsizedict .getdeviceparams
  249.   exch pop exch pop aload pop 3 2 roll
  250.   0 exch null exch .getbitsrect exch pop
  251. } bind odef
  252. currentdict /hwsizedict .undef
  253. /getdeviceprops
  254.  { null .getdeviceparams
  255.  } bind odef
  256. /.putdeviceprops
  257.  { null true counttomark 1 add 3 roll .putdeviceparams
  258.    dup type /booleantype ne
  259.     { dup mark eq { /unknown /rangecheck } if
  260.       counttomark 4 add 1 roll cleartomark pop pop pop
  261.       /.putdeviceprops load exch signalerror
  262.     }
  263.    if
  264.  } bind odef
  265. /max { .max } bind def
  266. /min { .min } bind def
  267. /.currentfilladjust { .currentfilladjust2 pop } bind odef
  268. /.setfilladjust { dup .setfilladjust2 } bind odef
  269. /unread /.unread load def
  270. /.writecvs { 0 .writecvp } bind odef
  271.  
  272. % Define predefined procedures substituting for operators,
  273. % in alphabetical order.
  274.  
  275. userdict /#copies 1 put
  276. % Adobe implementations don't accept /[ or /], so we don't either.
  277. ([) cvn
  278.     /mark load def
  279. (]) cvn
  280.     {counttomark array astore exch pop} odef
  281. % .beginpage is redefined if setpagedevice is present.
  282. /.beginpage { } odef
  283. % In LanguageLevel 3, copypage erases the page.
  284. /copypage {
  285.     .languagelevel 3 ge
  286.     dup { 0 } { 1 } ifelse .endpage {
  287.       .currentnumcopies 1 index .outputpage
  288.       (>>copypage, press <return> to continue<<\n) .confirm
  289.       dup { erasepage } if
  290.     } if pop .beginpage
  291. } odef
  292. /currentmatrix {
  293.     .currentmatrix 6 index astore pop
  294. } odef
  295. % .currentnumcopies is redefined in Level 2.
  296. /.currentnumcopies { #copies } odef
  297. /setcolorscreen where { pop        % not in all Level 1 configurations
  298.    /currentcolorscreen
  299.     { .currenthalftone
  300.        { { 60 exch 0 exch 3 copy 6 copy }    % halftone - not possible
  301.          { 3 copy 6 copy }            % screen
  302.          { }                % colorscreen
  303.        }
  304.       exch get exec
  305.     } odef
  306. } if
  307. /currentscreen
  308.     { .currenthalftone
  309.        { { 60 exch 0 exch }            % halftone - not possible
  310.          { }                % screen
  311.          { 12 3 roll 9 { pop } repeat }    % colorscreen
  312.        }
  313.       exch get exec
  314.     } odef
  315. /.echo /echo load def
  316. userdict /.echo.mode true put
  317. /echo    {dup /.echo.mode exch store .echo} odef
  318. /eexec {
  319.     % Rebind .currentresourcefile if it is the source for the eexec.
  320.   dup 55665 //filterdict /eexecDecode get exec
  321.   cvx exch .currentresourcefile eq
  322.   //systemdict begin { {exec} .execasresource } { exec } ifelse
  323.     % Only pop systemdict if it is still the top element,
  324.     % because this is apparently what Adobe interpreters do.
  325.   currentdict //systemdict eq { end } if
  326. } odef
  327. % .endpage is redefined if setpagedevice is present.
  328. /.endpage { 2 ne } odef
  329. % erasepage mustn't use gsave/grestore, because we call it before
  330. % the graphics state stack has been fully initialized.
  331. /erasepage
  332.     { /currentcolor where
  333.        { pop currentcolor currentcolorspace { setcolorspace setcolor } }
  334.        { /currentcmykcolor where
  335.           { pop currentcmykcolor { setcmykcolor } }
  336.           { currentrgbcolor { setrgbcolor } }
  337.          ifelse
  338.        }
  339.       ifelse 1 setgray .fillpage exec
  340.     } odef
  341. % To satisfy the Genoa FTS, executive must be a procedure, not an operator.
  342. /executive
  343.     { { prompt
  344.          { (%statementedit) (r) file } stopped
  345.          { pop pop $error /errorname get /undefinedfilename eq
  346.         { .clearerror exit } if        % EOF
  347.            handleerror null        % ioerror??
  348.          }
  349.         if
  350.         cvx { .runexec } execute
  351.       } loop
  352.     } bind def
  353. /filter
  354.     { //filterdict 1 index .knownget
  355.        { exch pop exec }
  356.        { /filter load /undefined signalerror }
  357.       ifelse
  358.     } odef
  359. /handleerror
  360.     { /errordict .systemvar /handleerror get exec } bind def
  361. /identmatrix [1.0 0.0 0.0 1.0 0.0 0.0] readonly def
  362. /identmatrix
  363.     { dup 0 //identmatrix putinterval } odef
  364. /languagelevel 1 def        % gs_lev2.ps may change this
  365. /makeimagedevice { false makewordimagedevice } odef
  366. /matrix    { 6 array identmatrix } odef
  367. /pathbbox
  368.     { false .pathbbox
  369.     } odef
  370. % .promptmsg is redefined if the interpreter includes readline support.
  371. /.promptmsg {
  372.     (GS) print
  373.     count 0 ne { (<) print count =only } if
  374.     (>) print flush
  375. } bind def
  376. /prompt    { flush flushpage NOPROMPT not { .promptmsg } if } bind def
  377. /pstack    { 0 1 count 3 sub { index == } for } bind def
  378. /putdeviceprops
  379.     { .putdeviceprops { erasepage } if } odef
  380. /quit    { /quit load 0 .quit } odef
  381. /run    { dup type /filetype ne { (r) file } if
  382.         % We must close the file when execution terminates,
  383.         % regardless of the state of the stack,
  384.         % and then propagate an error, if any.
  385.       cvx .runexec
  386.     } odef
  387. % Execute a file.
  388. % Level 2 uses 2 .stop to clear the e-stack for a successful startjob:
  389. % we detect that here, since we need to handle this even if we start out
  390. % without job control in effect.
  391. %
  392. % What we push on the e-stack is the following to be executed in this order:
  393. %    <lit-file|fileproc> .runexec1 <lit-file|fileproc> .runexec2
  394. /.runexec1 {        % <file|fileproc> .runexec1 -
  395.   dup type /filetype ne { cvx exec } if
  396.   cvx null 2 .stopped
  397.     % If we got back here from a startjob, just keep going.
  398.     % startjob replaces the null on the o-stack with a procedure
  399.     % to be executed when we get back here.
  400.   dup null ne { exec true } { pop false } ifelse
  401. } bind def
  402. /.runexec2 {        % <continue> <file|fileproc> .runexec2 -
  403.   exch {
  404.     .runexec
  405.   } {
  406.     dup type /filetype ne { cvx exec } if
  407.     closefile
  408.   } ifelse
  409. } bind def
  410. /.runexec {        % <file|fileproc> .runexec -
  411.   cvlit /.runexec1 cvx 1 index /.runexec2 cvx 4 .execn
  412. } bind def
  413. % The following is only for compatibility with Adobe interpreters.
  414. /setdash {
  415.     1 index length 11 gt { /setdash load /limitcheck signalerror } if
  416.     //setdash
  417. } odef
  418. /setdevice
  419.     { .setdevice { erasepage } if } odef
  420. /setlinecap {
  421.     dup 2 gt { /setlinecap load /rangecheck signalerror } if
  422.     .setlinecap
  423. } odef
  424. /setlinejoin {
  425.     dup 2 gt { /setlinejoin load /rangecheck signalerror } if
  426.     .setlinejoin
  427. } odef
  428. /setmatrix {
  429.     dup aload pop .setmatrix pop
  430. } odef
  431. /showpage {
  432.     0 .endpage .doneshowpage {
  433.       .currentnumcopies true .outputpage
  434.       (>>showpage, press <return> to continue<<\n) .confirm
  435.       erasepage
  436.     } if initgraphics .beginpage
  437. } odef
  438. % Code output by Adobe Illustrator relies on the fact that
  439. % `stack' is a procedure, not an operator!!!
  440. /stack    { 0 1 count 3 sub { index = } for } bind def
  441. /start    { BATCH { null 0 .quit } { executive } ifelse } def
  442. % Internal uses of stopped that aren't going to do a stop if an error occurs
  443. % should use .internalstopped to avoid setting newerror et al.
  444. /.internalstopped { null 1 .stopped null ne } bind def
  445. /store {    % Don't alter operands before completing.
  446.     1 index where { 2 index 2 index put pop pop } { def } ifelse
  447. } odef
  448. /.typenames mark .typenames counttomark packedarray exch pop def
  449. /type {
  450.     //.typenames .type
  451. } odef
  452. currentdict /.typenames .undef
  453. % When running in Level 1 mode, this interpreter is supposed to be
  454. % compatible with PostScript "version" 54.0 (I think).
  455. /version (54.0) readonly def
  456. /.wheredict 10 dict def
  457. /.where /where load def
  458. /where {
  459.     //.wheredict 1 index .knownget { exec } { .where } ifelse
  460. } odef
  461.  
  462. % internaldict is defined in systemdict, but the dictionary is allocated
  463. % in local VM.  However, the procedure must be global, since it is an
  464. % "operator" and must be bind-able into global procedures.
  465. % We make a procedure for creating it, since we must create a new one
  466. % for each context with private local VM.
  467. /.makeinternaldict {
  468.   .currentglobal true .setglobal
  469.     [ /dup .systemvar 1183615869 /eq .systemvar
  470.     [ /pop .systemvar null ] cvx
  471.     false .setglobal
  472.     dup 1 10 dict .forceput    % proc is global, dict is local
  473.     true .setglobal
  474.     [ /internaldict /cvx .systemvar /invalidaccess /signalerror cvx ] cvx
  475.       /ifelse .systemvar
  476.     ] cvx executeonly
  477.   exch .setglobal
  478. } odef
  479. systemdict /internaldict dup .makeinternaldict .makeoperator
  480. .forceput        % proc is local, systemdict is global
  481. % Move superexec to internaldict if superexec is defined.
  482. currentdict /superexec .knownget {
  483.   1183615869 internaldict /superexec 3 -1 roll put
  484.   currentdict /superexec .undef
  485. } if
  486.  
  487. % Define some additional built-in procedures (beyond the ones defined by
  488. % the PostScript Language Reference Manual).
  489. % Warning: these are not guaranteed to stay the same from one release
  490. % to the next!
  491. /concatstrings
  492.     { exch dup length 2 index length add string    % str2 str1 new
  493.       dup dup 4 2 roll copy        % str2 new new new1
  494.       length 4 -1 roll putinterval
  495.     } bind def
  496. /copyarray
  497.     { dup length array copy } bind def
  498. % Copy a dictionary per the Level 2 spec even in Level 1.
  499. /.copydict        % <fromdict> <todict> .copydict <todict>
  500.     { dup 3 -1 roll { put dup } forall pop } bind def
  501. /copystring
  502.     { dup length string copy } bind def
  503. /findlibfile {
  504.     .libfile { dup .filename pop exch true } { false } ifelse
  505. } odef
  506. /.growdictlength    % get size for growing a dictionary
  507.     { length 3 mul 2 idiv 1 add
  508.     } bind def
  509. /.growdict        % grow a dictionary
  510.     { dup .growdictlength .setmaxlength
  511.     } bind def
  512. /.growput        % put, grow the dictionary if needed
  513.     { 2 index length 3 index maxlength eq
  514.        { 3 copy pop known not { 2 index .growdict } if
  515.        } if
  516.       put
  517.     } bind def
  518. % .localvmarray may be an operator: see zsysvm.c.
  519. /.localvmarray where {
  520.   pop
  521. } {
  522.   /.localvmarray {
  523.     .currentglobal false .setglobal
  524.     exch array exch .setglobal
  525.   } bind def
  526. } ifelse
  527. /.localvmdict where {
  528.   pop
  529. } {
  530.   /.localvmdict {
  531.     .currentglobal false .setglobal
  532.     exch dict exch .setglobal
  533.   } bind def
  534. } ifelse
  535. /.packtomark
  536.     { counttomark packedarray exch pop } bind def
  537. /ppstack
  538.     { 0 1 count 3 sub { index === } for } bind def
  539. /runlibfile
  540.     {        % We don't want to bind 'run' into this procedure,
  541.             % since run may get redefined.
  542.       findlibfile
  543.        { exch pop /run .systemvar exec }
  544.        { /undefinedfilename signalerror }
  545.       ifelse
  546.     } bind def
  547. /selectdevice
  548.     { finddevice setdevice .setdefaultscreen } bind def
  549. /signalerror        % <object> <errorname> signalerror -
  550.     { /errordict .systemvar exch get exec } bind def
  551.  
  552. % Define the =[only] procedures.  Also define =print,
  553. % which is used by some PostScript programs even though
  554. % it isn't documented anywhere.
  555. /write=only {
  556.     .writecvs
  557. } bind def
  558. /write= {
  559.     1 index exch write=only (\n) writestring
  560. } bind def
  561. /=only    { (%stdout) (w) file exch write=only } bind def
  562. /=    { =only (\n) print } bind def
  563. /=print    /=only load def
  564. % Temporarily define == as = for the sake of runlibfile0.
  565. /== /= load def
  566.  
  567. % The following procedures are documented.
  568. /copydevice {        % <device> copydevice <newdevice>
  569.   false .copydevice2
  570. } odef
  571. /finddevice {        % <devicename> finddevice <device>
  572.   /devicedict .systemvar exch get
  573.   dup 1 get null eq {
  574.         % This is the first request for this type of device.
  575.         % Create a default instance now.
  576.         % Stack: [proto null]
  577.     .currentglobal true .setglobal exch
  578.     dup dup 0 get copydevice 1 exch put
  579.     exch .setglobal
  580.   } if 1 get
  581. } bind def
  582. /findprotodevice {    % <devicename> findprotodevice <protodevice>
  583.   /devicedict .systemvar exch get 0 get
  584. } bind def
  585.  
  586. % Run a resource file.  This allows us to distinguish resource objects
  587. % from objects coming from input files.
  588. userdict /.currentresourcefile null put
  589. /.execasresource {    % <file> <proc|runfile> .execasresource -
  590.   /stopped .systemvar
  591.   /.currentresourcefile .uservar
  592.         % Stack: file proc -stopped- currfile
  593.   .userdict /.currentresourcefile 5 index cvlit put
  594.   2 .execn        % stopped <file>
  595.   .userdict /.currentresourcefile 3 -1 roll put
  596.   { stop } if
  597. } bind def
  598. /.runresource {        % <file> .runresource -
  599.   { /run .systemvar exec } .execasresource
  600. } bind def
  601.  
  602. % Define procedures for getting and setting the current device resolution.
  603.  
  604. /gsgetdeviceprop    % <device> <propname> gsgetdeviceprop <value>
  605.  { 2 copy mark exch null .dicttomark .getdeviceparams
  606.    dup mark eq        % if true, not found
  607.     { pop dup /undefined signalerror }
  608.     { 5 1 roll pop pop pop pop }
  609.    ifelse
  610.  } bind def
  611. /gscurrentresolution    % - gscurrentresolution <[xres yres]>
  612.  { currentdevice /HWResolution gsgetdeviceprop
  613.  } bind def
  614. /gssetresolution    % <[xres yres]> gssetresolution -
  615.  { 2 array astore mark exch /HWResolution exch
  616.    currentdevice copydevice putdeviceprops setdevice
  617.  } bind def
  618.  
  619. % Define auxiliary procedures needed for the above.
  620. /shellarguments        % -> shell_arguments true (or) false
  621.     { /ARGUMENTS where
  622.        { /ARGUMENTS get dup type /arraytype eq
  623.           { aload pop /ARGUMENTS null store true }
  624.           { pop false }
  625.          ifelse }
  626.        { false } ifelse
  627.     } bind def
  628. /.confirm {
  629.   DISPLAYING NOPAUSE not TTYPAUSE or and {
  630.     % Print a message (unless NOPAGEPROMPT or NOPROMPT is true)
  631.     % and wait for the user to type something.
  632.     % If the user just types a newline, flush it.
  633.     NOPAGEPROMPT NOPROMPT or { pop } { print flush } ifelse
  634.     .confirmread
  635.   } {
  636.     pop
  637.   } ifelse
  638. } bind def
  639. /.confirmread {
  640.   TTYPAUSE {
  641.     (/dev/tty) (r) file dup read pop pop closefile
  642.   } {
  643.     .echo.mode false echo
  644.     (%stdin) (r) file dup read {
  645.       dup (\n) 0 get eq { pop pop } { unread } ifelse
  646.     } {
  647.       pop
  648.     } ifelse echo
  649.   } ifelse
  650. } bind def
  651.  
  652. % Define the procedure used by .runfile, .runstdin and .runstring
  653. % for executing user input.
  654. % This is called with a procedure or executable file on the operand stack.
  655. /.execute {        % <obj> .execute <stopped>
  656.   stopped $error /newerror get and
  657.    { handleerror flush true } { false } ifelse
  658. } bind def
  659. /execute {        % <obj> execute -
  660.   .execute pop
  661. } odef
  662. % Define an execute analogue of runlibfile0.
  663. /execute0 {        % <obj> execute0 -
  664.   .execute { /execute0 cvx 1 .quit } if
  665. } bind def
  666. % Define the procedure that the C code uses for running files
  667. % named on the command line.
  668. /.runfile {
  669.   { runlibfile } execute0
  670. } def
  671. % Define the procedure that the C code uses for running piped input.
  672. % We don't use the obvious { (%stdin) run }, because we want the file to be
  673. % reopened if a startjob does a restore.
  674. /.runstdin {
  675.   { { (%stdin) (r) file cvx } .runexec } execute0
  676. } bind def
  677. % Define the procedure that the C code uses for running commands
  678. % given on the command line with -c.  We turn the string into a file so that
  679. % .runexec can do the right thing with a startjob.
  680. /.runstring {
  681.   .currentglobal exch true .setglobal
  682.   0 () .subfiledecode
  683.   exch .setglobal cvx { .runexec } execute0
  684. } bind def
  685. % Define the procedure that the C code uses to set up for executing
  686. % a string that may be received in pieces.
  687. /.runstringbegin {
  688.   .currentglobal true .setglobal
  689.   { .needinput } bind 0 () .subfiledecode
  690.   exch .setglobal cvx .runexec
  691. } bind def
  692.  
  693. % Define a special version of runlibfile that aborts on errors.
  694. /runlibfile0
  695.     { cvlit dup /.currentfilename exch def
  696.        { findlibfile not { stop } if }
  697.       stopped
  698.        { (Can't find \(or open\) initialization file ) print
  699.          .currentfilename == flush /runlibfile0 cvx 1 .quit
  700.        } if
  701.       exch pop cvx stopped
  702.        { (While reading ) print .currentfilename print (:\n) print flush
  703.          handleerror /runlibfile0 1 .quit
  704.        } if
  705.     } bind def
  706. % Temporarily substitute it for the real runlibfile.
  707. /.runlibfile /runlibfile load def
  708. /runlibfile /runlibfile0 load def
  709.  
  710. % Create the error handling machinery.
  711. % Define the standard error handlers.
  712. % The interpreter has created the ErrorNames array.
  713. /.unstoppederrorhandler    % <command> <errorname> .unstoppederrorhandler -
  714.  {    % This is the handler that gets used for recursive errors,
  715.     % or errors outside the scope of a 'stopped'.
  716.    2 copy SHORTERRORS
  717.     { (%%[ Error: ) print =only flush
  718.       (; OffendingCommand: ) print =only ( ]%%) =
  719.     }
  720.     { (Unrecoverable error: ) print =only flush
  721.       ( in ) print = flush
  722.       count 2 gt
  723.        { (Operand stack:\n  ) print
  724.      2 1 count 3 sub { (  ) print index =only flush } for
  725.      () = flush
  726.        } if
  727.     }
  728.    ifelse
  729.    -1 0 1 //ErrorNames length 1 sub
  730.     { dup //ErrorNames exch get 3 index eq
  731.        { not exch pop exit } { pop } ifelse
  732.     }
  733.    for exch pop .quit
  734.  } bind def
  735. /.errorhandler        % <command> <errorname> .errorhandler -
  736.   {        % Detect an internal 'stopped'.
  737.     1 .instopped { null eq { pop pop stop } if } if
  738.     $error /.inerror get 1 .instopped { pop } { pop true } ifelse
  739.      { .unstoppederrorhandler
  740.      } if    % detect error recursion
  741.     $error /globalmode .currentglobal false .setglobal put
  742.     $error /.inerror true put
  743.     $error /newerror true put
  744.     $error exch /errorname exch put
  745.     $error exch /command exch put
  746.     $error /recordstacks get $error /errorname get /VMerror ne and
  747.      {        % Attempt to store the stack contents atomically.
  748.        count array astore dup $error /ostack 4 -1 roll
  749.        countexecstack array execstack $error /estack 3 -1 roll
  750.        countdictstack array dictstack $error /dstack 3 -1 roll
  751.        put put put aload pop
  752.      }
  753.      { $error /dstack .undef
  754.        $error /estack .undef
  755.        $error /ostack .undef
  756.      }
  757.     ifelse
  758.     $error /position currentfile status
  759.      { currentfile { fileposition } .internalstopped { pop null } if
  760.      }
  761.      {        % If this was a scanner error, the file is no longer current,
  762.         % but the command holds the file, which may still be open.
  763.        $error /command get dup type /filetype eq
  764.         { { fileposition } .internalstopped { pop null } if }
  765.         { pop null }
  766.        ifelse
  767.      }
  768.     ifelse put
  769.         % During initialization, we don't reset the allocation
  770.         % mode on errors.
  771.     $error /globalmode get $error /.nosetlocal get and .setglobal
  772.     $error /.inerror false put
  773.     stop
  774.   } bind def
  775. % Define the standard handleerror.  We break out the printing procedure
  776. % (.printerror) so that it can be extended for binary output
  777. % if the Level 2 facilities are present.
  778.   /.printerror
  779.    { $error begin
  780.        /command load errorname SHORTERRORS
  781.     { (%%[ Error: ) print =only flush
  782.       (; OffendingCommand: ) print =only
  783.       errorinfo dup null eq {
  784.         pop
  785.       } {
  786.         (;\nErrorInfo:) print
  787.         dup type /arraytype eq
  788.           { { ( ) print =only } forall }
  789.           { ( ) print =only }
  790.         ifelse
  791.       } ifelse
  792.           ( ]%%) = flush
  793.     }
  794.     { (Error: ) print ==only flush
  795.       ( in ) print ==only flush
  796.       errorinfo dup null eq {
  797.         pop
  798.       } {
  799.         (\nAdditional information: ) print ==only flush
  800.       } ifelse
  801.       .printerror_long
  802.     }
  803.        ifelse
  804.        .clearerror
  805.      end
  806.      flush
  807.     } bind def     
  808.   /.printerror_long            % long error printout,
  809.                     % $error is on the dict stack
  810.    {    % Push the (anonymous) stack printing procedure.
  811.     %  <heading> <==flag> <override-name> <stackname> proc
  812.        {
  813.      currentdict exch .knownget    % stackname defined in $error?
  814.      {
  815.        4 1 roll            % stack: <stack> <head> <==flag> <over>
  816.        errordict exch .knownget    % overridename defined?
  817.        { 
  818.          exch pop exch pop exec    % call override with <stack>
  819.        }
  820.        { 
  821.          exch print exch        % print heading. stack <==flag> <stack>
  822.          1 index not { () = } if
  823.          { 1 index { (\n    ) } { (   ) } ifelse print
  824.            dup type /dicttype eq
  825.            {
  826.          (--dict:) print
  827.          dup rcheck {
  828.            dup length =only (/) print dup maxlength =only
  829.            dup wcheck not { ((ro)) print } if
  830.          } if
  831.          /gcheck where {
  832.            pop gcheck { ((G)) } { ((L)) } ifelse print
  833.          } {
  834.            pop
  835.          } ifelse (--) print
  836.            }
  837.            {
  838.          dup type /stringtype eq 2 index or
  839.          { ==only } { =only } ifelse
  840.            } ifelse
  841.          } forall
  842.          pop
  843.        }
  844.        ifelse            % overridden
  845.      }
  846.      { pop pop pop
  847.      }
  848.      ifelse                % stack known
  849.        }
  850.  
  851.        (\nOperand stack:) OSTACKPRINT /.printostack /ostack 4 index exec
  852.        (\nExecution stack:) ESTACKPRINT /.printestack /estack 4 index exec
  853.        (\nBacktrace:) true /.printbacktrace /backtrace 4 index exec
  854.        (\nDictionary stack:) false /.printdstack /dstack 4 index exec
  855.        () =
  856.        pop    % printing procedure
  857.  
  858.        errorname /VMerror eq
  859.     { (VM status:) print mark vmstatus
  860.       counttomark { ( ) print counttomark -1 roll dup =only } repeat
  861.       cleartomark () =
  862.     } if
  863.  
  864.        .languagelevel 2 ge
  865.     { (Current allocation mode is ) print
  866.       globalmode { (global\n) } { (local\n) } ifelse print
  867.     } if
  868.  
  869.        .oserrno dup 0 ne
  870.     { (Last OS error: ) print
  871.       errorname /VMerror ne
  872.        { dup .oserrorstring { = pop } { = } ifelse }
  873.        { = }
  874.       ifelse
  875.     }
  876.     { pop
  877.     }
  878.        ifelse
  879.  
  880.        position null ne
  881.     { (Current file position is ) print position = }
  882.        if
  883.  
  884.    } bind def
  885. % Define a procedure for clearing the error indication.
  886. /.clearerror
  887.  { $error /newerror false put
  888.    $error /errorname null put
  889.    $error /errorinfo null put
  890.    0 .setoserrno
  891.  } bind def
  892.  
  893. % Define $error.  This must be in local VM.
  894. .currentglobal false .setglobal
  895. /$error 40 dict .forcedef    % $error is local, systemdict is global
  896.         % newerror, errorname, command, errorinfo,
  897.         % ostack, estack, dstack, recordstacks,
  898.         % binary, globalmode,
  899.         % .inerror, .nosetlocal, position,
  900.         % plus extra space for badly designed error handers.
  901. $error begin
  902.   /newerror false def
  903.   /recordstacks true def
  904.   /binary false def
  905.   /globalmode .currentglobal def
  906.   /.inerror false def
  907.   /.nosetlocal true def
  908.   /position null def
  909. end
  910. % Define errordict similarly.  It has one entry per error name,
  911. %   plus handleerror.  However, some astonishingly badly written PostScript
  912. %   files require it to have at least one empty slot.
  913. /errordict ErrorNames length 2 add dict
  914. .forcedef        % errordict is local, systemdict is global
  915. .setglobal        % contents of errordict are global
  916. errordict begin
  917.   ErrorNames
  918.    { mark 1 index systemdict /.errorhandler get /exec load .packtomark cvx def
  919.    } forall
  920. % The handlers for interrupt and timeout are special; there is no
  921. % 'current object', so they push their own name.
  922.    { /interrupt /timeout }
  923.    { mark 1 index dup systemdict /.errorhandler get /exec load .packtomark cvx def
  924.    } forall
  925. /handleerror
  926.  { /.printerror .systemvar exec
  927.  } bind def
  928. end
  929.  
  930. % Define the [write]==[only] procedures.
  931. /.dict 8 dict dup
  932. begin def
  933.   /.cvp {1 index exch 1 .writecvp} bind def
  934.   /.p {1 index exch writestring} bind def
  935.   /.p1 {2 index exch writestring} bind def
  936.   /.p2 {3 index exch writestring} bind def
  937.   /.print
  938.     { dup type .dict exch .knownget { exec } { .cvp } ifelse
  939.     } bind def
  940.   /arraytype
  941.     {dup rcheck
  942.       {() exch dup xcheck
  943.         {({) .p2
  944.          {exch .p1
  945.           1 index exch .print pop ( )} forall
  946.          (})}
  947.         {([) .p2
  948.          {exch .p1
  949.           1 index exch .print pop ( )} forall
  950.          (])}
  951.        ifelse exch pop .p}
  952.       {.cvp}
  953.      ifelse} bind def
  954.   /packedarraytype /arraytype load def
  955. {//.dict begin .print pop end}
  956.   bind
  957. end
  958.  
  959. /write==only exch def
  960. /write== {1 index exch write==only (\n) writestring} bind def
  961. /==only { (%stdout) (w) file exch write==only } bind def
  962. /== {==only (\n) print} bind def
  963.  
  964. % Define [write]===[only], an extension that prints dictionaries
  965. % in readable form and doesn't truncate strings.
  966. /.dict /write==only load 0 get dup length 2 add dict .copydict dup
  967. begin def
  968.   /dicttype
  969.     { dup rcheck
  970.        { (<< ) .p1
  971.           { 2 index 3 -1 roll .print pop ( ) .p1
  972.         1 index exch .print pop ( ) .p
  973.           }
  974.          forall (>>) .p
  975.        }
  976.        { .cvp
  977.        }
  978.       ifelse
  979.     } bind def
  980.   /stringtype
  981.     { 1 index exch 2 .writecvp
  982.     } bind def
  983.  
  984. {//.dict begin .print pop end}
  985.   bind
  986. end
  987.  
  988. /write===only exch def
  989. /write=== {1 index exch write===only (\n) writestring} bind def
  990. /===only { (%stdout) (w) file exch write===only } bind def
  991. /=== { ===only (\n) print } bind def
  992.  
  993. (END PROCS) VMDEBUG
  994.  
  995. % Define the font directory.
  996. /FontDirectory false .setglobal 100 dict true .setglobal
  997. .forcedef        % FontDirectory is local, systemdict is global
  998.  
  999. % Define the encoding dictionary.
  1000. /EncodingDirectory 16 dict def    % enough for Level 2 + PDF standard encodings
  1001.  
  1002. % Define .findencoding.  (This is redefined in Level 2.)
  1003. /.findencoding
  1004.  { //EncodingDirectory exch get exec
  1005.  } bind def
  1006. /.defineencoding
  1007.  { //EncodingDirectory 3 1 roll put
  1008.  } bind def
  1009. % If we've got the composite font extensions, define findencoding.
  1010. % To satisfy the Genoa FTS, findencoding must be a procedure, not an operator.
  1011. /rootfont where { pop /findencoding { .findencoding } def } if
  1012.  
  1013. % Define .registerencoding.
  1014. % NOTE: the name registeredencodings is known to (initialized by and shared
  1015. % with) the interpreter.
  1016. /.registerencoding {    % <index> <array> .registerencoding -
  1017.     % Check that the array is indexable.
  1018.     % (It might still be a string, but then the .namestring will fail.)
  1019.   dup 0 0 getinterval pop
  1020.     % Check that all the elements of the array are names.
  1021.   dup { .namestring pop } forall
  1022.     % Do the store.
  1023.   //registeredencodings 2 index 2 index readonly put pop pop
  1024. } bind odef
  1025. systemdict /registeredencodings .undef
  1026.  
  1027. % Load StandardEncoding.
  1028. %% Replace 1 (gs_std_e.ps)
  1029. (gs_std_e.ps) dup runlibfile VMDEBUG
  1030.  
  1031. % Load ISOLatin1Encoding.
  1032. %% Replace 1 (gs_il1_e.ps)
  1033. (gs_il1_e.ps) dup runlibfile VMDEBUG
  1034.  
  1035. % Define stubs for the Symbol and Dingbats encodings.
  1036. % Note that the first element of the procedure must be the file name,
  1037. % since gs_lev2.ps extracts it to set up the Encoding resource category.
  1038.  
  1039.   /SymbolEncoding { /SymbolEncoding .findencoding } bind def
  1040. %% Replace 3 (gs_sym_e.ps)
  1041.   EncodingDirectory /SymbolEncoding
  1042.    { (gs_sym_e.ps) //systemdict begin runlibfile SymbolEncoding end }
  1043.   bind put
  1044.  
  1045.   /DingbatsEncoding { /DingbatsEncoding .findencoding } bind def
  1046. %% Replace 3 (gs_dbt_e.ps)
  1047.   EncodingDirectory /DingbatsEncoding
  1048.    { (gs_dbt_e.ps) //systemdict begin runlibfile DingbatsEncoding end }
  1049.   bind put
  1050.  
  1051. (END FONTDIR/ENCS) VMDEBUG
  1052.  
  1053. % Construct a dictionary of all available devices.
  1054. % These are (read-only) device prototypes that can't be
  1055. % installed or have their parameters changed.  For this reason,
  1056. % the value in the dictionary is actually a 2-element writable array,
  1057. % to allow us to create a default instance of the prototype on demand.
  1058.  
  1059.     % Loop until the .getdevice gets a rangecheck.
  1060. errordict /rangecheck 2 copy get
  1061. errordict /rangecheck { pop stop } put    % pop the command
  1062.   0 { {dup .getdevice exch 1 add} loop} .internalstopped pop
  1063.   1 add dict  /devicedict 1 index def
  1064.   begin            % 2nd copy of count is on stack
  1065.    { dup .devicename exch
  1066.      dup wcheck { dup } { null } ifelse 2 array astore def
  1067.    } repeat
  1068.   end
  1069. put        % errordict /rangecheck
  1070. .clearerror
  1071. /devicenames devicedict { pop } forall devicedict length packedarray def
  1072.  
  1073. % Determine the default device.
  1074. /defaultdevice DISPLAYING
  1075.  { systemdict /DEVICE .knownget
  1076.     { devicedict 1 index known not
  1077.        { (Unknown device: ) print =
  1078.      flush /defaultdevice cvx 1 .quit
  1079.        }
  1080.       if
  1081.     }
  1082.     { 0 .getdevice .devicename
  1083.     }
  1084.    ifelse
  1085.  }
  1086.  { /nullpage
  1087.  }
  1088. ifelse
  1089. /.defaultdevicename 1 index def
  1090. finddevice    % make a copy
  1091. def
  1092. devicedict /Default devicedict .defaultdevicename get put
  1093.  
  1094. (END DEVS) VMDEBUG
  1095.  
  1096. % Define statusdict, for the benefit of programs
  1097. % that think they are running on a LaserWriter or similar printer.
  1098. %% Replace 1 (gs_statd.ps)
  1099. (gs_statd.ps) runlibfile
  1100.  
  1101. (END STATD) VMDEBUG
  1102.  
  1103. % Load the standard font environment.
  1104. %% Replace 1 (gs_fonts.ps)
  1105. (gs_fonts.ps) runlibfile
  1106.  
  1107. (END GS_FONTS) VMDEBUG
  1108.  
  1109. % Define the default halftone screen and BG/UCR functions now, so that
  1110. % it will bind in the original definitions of set[color]screen.
  1111. % We make this a procedure so we can call it again when switching devices.
  1112.  
  1113. % Use an ordered dither for low-resolution devices.
  1114. /.setloreshalftone {    % <dpi> .setloreshalftone -
  1115.     % The following 'ordered dither' spot function was contributed by
  1116.     % Gregg Townsend.  Thanks, Gregg!
  1117.    16.001 div 0            % not 16: avoids rounding problems
  1118.     { 1 add 7.9999 mul cvi exch 1 add 7.9999 mul cvi 16 mul add <
  1119.     0E 8E 2E AE 06 86 26 A6 0C 8C 2C AC 04 84 24 A4
  1120.     CE 4E EE 6E C6 46 E6 66 CC 4C EC 6C C4 44 E4 64
  1121.     3E BE 1E 9E 36 B6 16 96 3C BC 1C 9C 34 B4 14 94
  1122.     FE 7E DE 5E F6 76 D6 56 FC 7C DC 5C F4 74 D4 54
  1123.     01 81 21 A1 09 89 29 A9 03 83 23 A3 0B 8B 2B AB
  1124.     C1 41 E1 61 C9 49 E9 69 C3 43 E3 63 CB 4B EB 6B
  1125.     31 B1 11 91 39 B9 19 99 33 B3 13 93 3B BB 1B 9B
  1126.     F1 71 D1 51 F9 79 D9 59 F3 73 D3 53 FB 7B DB 5B
  1127.     0D 8D 2D AD 05 85 25 A5 0F 8F 2F AF 07 87 27 A7
  1128.     CD 4D ED 6D C5 45 E5 65 CF 4F EF 6F C7 47 E7 67
  1129.     3D BD 1D 9D 35 B5 15 95 3F BF 1F 9F 37 B7 17 97
  1130.     FD 7D DD 5D F5 75 D5 55 FF 7F DF 5F F7 77 D7 57
  1131.     02 82 22 A2 0A 8A 2A AA 00 80 20 A0 08 88 28 A8
  1132.     C2 42 E2 62 CA 4A EA 6A C0 40 E0 60 C8 48 E8 68
  1133.     32 B2 12 92 3A BA 1A 9A 30 B0 10 90 38 B8 18 98
  1134.     F2 72 D2 52 FA 7A DA 5A F0 70 D0 50 F8 78 D8 58
  1135.      > exch get 256 div
  1136.     }
  1137.    bind
  1138.         % Use correct, per-plane screens for CMYK devices only.
  1139.    //systemdict /setcolorscreen known processcolors 4 eq and
  1140.     { 3 copy 6 copy //setcolorscreen }
  1141.     { //setscreen }
  1142.    ifelse
  1143. } bind def
  1144. /.setloresscreen {    % <dpi> .setloresscreen -
  1145.   .setloreshalftone
  1146.   0 array cvx settransfer    % Genoa CET won't accept a packed array!
  1147.   /setstrokeadjust where { pop true setstrokeadjust } if
  1148. } bind def
  1149. % Use a 45-degree spot screen for high-resolution devices.
  1150. /.sethireshalftone {    % <dpi> .sethireshalftone <doscreen>
  1151.     % According to information published by Hewlett-Packard,
  1152.     % they use a 60 line screen on 300 DPI printers and
  1153.     % an 85 line screen on 600 DPI printers.
  1154.     % However, we use a 106 line screen, which produces smoother-
  1155.     % looking shades but fewer of them (32 vs. 50).
  1156.     % 46 was suggested as a good frequency value for printers
  1157.     % between 200 and 400 DPI, so we use it for lower resolutions.
  1158.     % Imagesetters need even higher frequency screens.
  1159.    //systemdict /DITHERPPI known
  1160.     { DITHERPPI
  1161.     }
  1162.     { dup cvi 100 idiv 15 .min
  1163.        {null 46 46 60 60 60 106 106 106 106 133 133 133 133 133 150}
  1164.       exch get
  1165.      }
  1166.    ifelse
  1167.    1 index 4.01 div .min    % at least a 4x4 cell
  1168.    45
  1169.     % The following screen algorithm is used by permission of the author.
  1170.     { 1 add 180 mul cos 1 0.08 add mul exch 2 add 180 mul cos 
  1171.       1 0.08 sub mul add 2 div % (C) 1989 Berthold K.P. Horn
  1172.     }
  1173.    bind
  1174.     % Determine whether we have lots of process colors.
  1175.     % If so, don't bother with color screening or gamma correction.
  1176.     % Also don't do gamma correction on very high-resolution devices.
  1177.     % (This should depend on dot gain, not resolution, but we don't
  1178.     % currently have a way to determine this.)
  1179.    currentdevice mark
  1180.      /RedValues 0 /GreenValues 0 /BlueValues 0 /GrayValues 0
  1181.    .dicttomark .getdeviceparams
  1182.    counttomark 2 idiv 1 sub { exch pop min } repeat
  1183.    exch pop exch pop 32 lt 4 index 800 lt and 5 1 roll
  1184.     % Stack: doscreen dpi freq angle proc
  1185.     % Ghostscript currently doesn't use correct, per-plane halftones
  1186.     % unless setcolorscreen has been executed.  Since these are
  1187.     % computationally much more expensive than binary halftones,
  1188.     % we check to make sure they are really warranted, i.e., we have
  1189.     % a high-resolution CMYK device (i.e., not a display) with
  1190.     % fewer than 5 bits per plane (i.e., not a true-color device).
  1191.    4 -1 roll 150 ge
  1192.     { /setcolorscreen where
  1193.        { pop //systemdict /COLORSCREEN known
  1194.       { COLORSCREEN }
  1195.       { 3 index }
  1196.      ifelse
  1197.      dup false ne
  1198.       { 4 1 roll 3 copy 6 copy 13 -1 roll
  1199.     % For really high-quality screening on printers, we need to
  1200.     % give each plane its own screen angle.  Unfortunately,
  1201.     % this currently has very large space and time costs.
  1202.         true eq        % true => different angles,
  1203.                 % 0 => same angles
  1204.          { { 45 90 15 75 } { 3 1 roll exch pop 12 3 roll } forall
  1205.          }
  1206.         if //setcolorscreen
  1207.       }
  1208.       { pop //setscreen    % false => single binary screen
  1209.       }
  1210.      ifelse
  1211.        }
  1212.        { //setscreen        % setcolorscreen not known
  1213.        }
  1214.       ifelse
  1215.     }
  1216.     { //setscreen            % not high resolution
  1217.     }
  1218.    ifelse
  1219. } bind def
  1220. /.sethiresscreen {    % <dpi> .sethiresscreen -
  1221.   .sethireshalftone
  1222.             % Stack: doscreen
  1223.     {    % Set the transfer function to lighten up the grays.
  1224.     % We correct at the high end so that very light grays
  1225.     % don't disappear completely if they darken <1 screen pixel.
  1226.     % Parameter values closer to 1 are better for devices with
  1227.     % less dot spreading; lower values are better with more spreading.
  1228.     % The value 0.8 is a compromise that will probably please no one!
  1229.     %
  1230.     % Because of a bug in FrameMaker, we have to accept operands
  1231.     % outside the valid range of [0..1].
  1232.       { dup dup 0.0 gt exch 1.0 lt and
  1233.      { 0.8 exp dup dup 0.9375 gt exch 0.999 lt and    % > 15/16
  1234.         { .currentscreenlevels 1 sub    % tweak to avoid boundary
  1235.           1 exch div 1 exch sub .min
  1236.         }
  1237.        if
  1238.      }
  1239.     if
  1240.       }
  1241.     }
  1242.     {    % Set the transfer function to the identity.
  1243.       0 array cvx        % Genoa CET won't accept a packed array!
  1244.     }
  1245.    ifelse settransfer
  1246.    /setstrokeadjust where { pop false setstrokeadjust } if
  1247.     % Increase fill adjustment so that we effectively use Adobe's
  1248.     % any-part-of-pixel rule.
  1249.    0.5 .setfilladjust
  1250. } bind def
  1251. % Set the default screen and BG/UCR.
  1252. /.setdefaultbgucr {
  1253.   systemdict /setblackgeneration known {
  1254.     { pop 0 } dup setblackgeneration setundercolorremoval
  1255.   } if
  1256. } bind def
  1257. /.useloresscreen {    % - .useloresscreen <bool>
  1258.     % Compute min(|dpi x|,|dpi y|) as the definition of the resolution.
  1259.   72 72 matrix defaultmatrix dtransform abs exch abs .min
  1260.   dup 150 lt //systemdict /DITHERPPI known not and
  1261. } bind def
  1262.  
  1263. % The following implementation uses LL2 extensions, but only in stopped
  1264. % contexts so that with LL1, the .set??reshalftone will be used.
  1265. %
  1266. %    - .getdefaulthalftone <halftonedict> true    if default found
  1267. %                  false            
  1268. /.getdefaulthalftone {
  1269.   % try the device to see if it has a default halftone
  1270.   { currentdevice /HalftoneDefault gsgetdeviceprop } stopped
  1271.   { pop pop false }        % no device property
  1272.   { dup type /dicttype eq { true } { pop false } ifelse }
  1273.   ifelse
  1274.   % stack: <halftonedict> true    if default found
  1275.   %         false          not found
  1276.   dup not
  1277.   { % device did not provide a default, try Resource
  1278.     pop { /Default /Halftone /findresource .systemvar exec } stopped 
  1279.     { pop pop false } { true } ifelse
  1280.   }
  1281.   if
  1282. } bind def
  1283.  
  1284. /.setdefaulthalftone {
  1285.   .getdefaulthalftone 
  1286.   { sethalftone }
  1287.   { % default not found
  1288.     .useloresscreen { .setloreshalftone } { .sethireshalftone pop } ifelse
  1289.   }
  1290.   ifelse
  1291. } bind def
  1292.  
  1293. /.setdefaultscreen {
  1294.   .useloresscreen { .setloresscreen } { .sethiresscreen } ifelse
  1295.   .setdefaultbgucr
  1296. } bind def
  1297.  
  1298. % Load the initialization files for optional features.
  1299. %% Replace 4 INITFILES
  1300. systemdict /INITFILES known
  1301.  { INITFILES { dup runlibfile VMDEBUG } forall
  1302.  }
  1303. if
  1304.  
  1305. % If Level 2 (or higher) functionality is implemented, enable it now.
  1306. /.setlanguagelevel where {
  1307.   pop 2 .setlanguagelevel
  1308.     % If the resource machinery is loaded, fix up some things now.
  1309.   /.fixresources where { pop .fixresources } if
  1310. } if
  1311. /ll3dict where {
  1312.   pop 3 .setlanguagelevel
  1313. } if
  1314.  
  1315. (END INITFILES) VMDEBUG
  1316.  
  1317. % Create a null font.  This is the initial font.
  1318. 8 dict dup begin
  1319.   /FontMatrix [ 1 0 0 1 0 0 ] readonly def
  1320.   /FontType 3 def
  1321.   /FontName () def
  1322.   /Encoding StandardEncoding def
  1323.   /FontBBox { 0 0 0 0 } readonly def % executable is bogus, but customary ...
  1324.   /BuildChar { pop pop 0 0 setcharwidth } bind def
  1325.   /PaintType 0 def        % shouldn't be needed!
  1326. end
  1327. /NullFont exch definefont setfont
  1328.  
  1329. % Define NullFont as the font.
  1330. /NullFont currentfont def
  1331.  
  1332. % Load initial fonts from FONTPATH directories, Fontmap file,
  1333. % and/or .getccfont as appropriate.
  1334. .loadinitialfonts
  1335.  
  1336. % Remove NullFont from FontDirectory, so it can't be accessed by mistake.
  1337. /undefinefont where {
  1338.   pop /NullFont undefinefont
  1339. } {
  1340.   FontDirectory /NullFont .undef
  1341. } ifelse
  1342.  
  1343. (END FONTS) VMDEBUG
  1344.  
  1345. % Restore the real definition of runlibfile.
  1346. /runlibfile /.runlibfile load def
  1347. currentdict /.runlibfile .undef
  1348.  
  1349. % Bind all the operators defined as procedures.
  1350. /.bindoperators        % binds operators in currentdict
  1351.  { % Temporarily disable the typecheck error.
  1352.    errordict /typecheck 2 copy get
  1353.    errordict /typecheck { pop } put    % pop the command
  1354.    currentdict
  1355.     { dup type /operatortype eq
  1356.        { % This might be a real operator, so bind might cause a typecheck,
  1357.      % but we've made the error a no-op temporarily.
  1358.      .bind        % do a real bind even if NOBIND is set
  1359.        }
  1360.       if pop pop
  1361.     } forall
  1362.    put
  1363.  } def
  1364. NOBIND DELAYBIND or not { .bindoperators } if
  1365.  
  1366. % Establish a default environment.
  1367.  
  1368. defaultdevice
  1369. % The following line used to skip setting of page size and resolution if
  1370. % NODISPLAY was selected.  We think this was only to save time and memory,
  1371. % and it is a bad idea because it prevents setting the resolution in this
  1372. % situation, which pstoedit (among other programs) relies on.
  1373. %DISPLAYING not { setdevice (%END DISPLAYING) .skipeof } if
  1374. systemdict /DEVICEWIDTH known
  1375. systemdict /DEVICEHEIGHT known or
  1376. systemdict /DEVICEWIDTHPOINTS known or
  1377. systemdict /DEVICEHEIGHTPOINTS known or
  1378. systemdict /DEVICEXRESOLUTION known or
  1379. systemdict /DEVICEYRESOLUTION known or
  1380. systemdict /PAPERSIZE known or
  1381. not { (%END DEVICE) .skipeof } if
  1382. % Let DEVICE{WIDTH,HEIGHT}[POINTS] override PAPERSIZE.
  1383. systemdict /PAPERSIZE known
  1384. systemdict /DEVICEWIDTH known not and
  1385. systemdict /DEVICEHEIGHT known not and
  1386. systemdict /DEVICEWIDTHPOINTS known not and
  1387. systemdict /DEVICEHEIGHTPOINTS known not and
  1388.  {    % Convert the paper size to device dimensions.
  1389.    true statusdict /.pagetypenames get
  1390.     { PAPERSIZE eq
  1391.        { PAPERSIZE load
  1392.          dup 0 get /DEVICEWIDTHPOINTS exch def
  1393.          1 get /DEVICEHEIGHTPOINTS exch def
  1394.          pop false exit
  1395.        }
  1396.       if
  1397.     }
  1398.    forall
  1399.     { (Unknown paper size: ) print PAPERSIZE ==only (.) =
  1400.     }
  1401.    if
  1402.  }
  1403. if
  1404. % Adjust the device parameters per the command line.
  1405. % It is possible to specify resolution, pixel size, and page size;
  1406. % since any two of these determine the third, conflicts are possible.
  1407. % We simply pass them to .setdeviceparams and let it sort things out.
  1408.    mark /HWResolution null /HWSize null /PageSize null .dicttomark
  1409.    .getdeviceparams .dicttomark begin
  1410.    mark
  1411.     % Check for resolution.
  1412.    /DEVICEXRESOLUTION where dup
  1413.     { exch pop HWResolution 0 DEVICEXRESOLUTION put }
  1414.    if
  1415.    /DEVICEYRESOLUTION where dup
  1416.     { exch pop HWResolution 1 DEVICEYRESOLUTION put }
  1417.    if
  1418.    or { /HWResolution HWResolution } if
  1419.     % Check for device sizes specified in pixels.
  1420.    /DEVICEWIDTH where dup
  1421.     { exch pop HWSize 0 DEVICEWIDTH put }
  1422.    if
  1423.    /DEVICEHEIGHT where dup
  1424.     { exch pop HWSize 1 DEVICEHEIGHT put }
  1425.    if
  1426.    or { /HWSize HWSize } if
  1427.     % Check for device sizes specified in points.
  1428.    /DEVICEWIDTHPOINTS where dup
  1429.     { exch pop PageSize 0 DEVICEWIDTHPOINTS put }
  1430.    if
  1431.    /DEVICEHEIGHTPOINTS where dup
  1432.     { exch pop PageSize 1 DEVICEHEIGHTPOINTS put }
  1433.    if
  1434.    or { /PageSize PageSize } if
  1435.     % Check whether any parameters were set.
  1436.    dup mark eq { pop } { defaultdevice putdeviceprops } ifelse
  1437.    end
  1438. %END DEVICE
  1439. % Set any device properties defined on the command line.
  1440. % If BufferSpace is defined but not MaxBitmap, set MaxBitmap to BufferSpace.
  1441. systemdict /BufferSpace known
  1442. systemdict /MaxBitmap known not and
  1443.  { systemdict /MaxBitmap BufferSpace put
  1444.  } if
  1445. dup getdeviceprops
  1446. counttomark 2 idiv
  1447.  { systemdict 2 index known
  1448.     { pop dup load counttomark 2 roll }
  1449.     { pop pop }
  1450.    ifelse
  1451.  } repeat
  1452. counttomark dup 0 ne
  1453.  { 2 add -1 roll putdeviceprops }
  1454.  { pop pop }
  1455. ifelse
  1456. % If the initial device parameters are invalid, the setdevice may fail.
  1457. % Trap this and produce a reasonable error message.
  1458. { setdevice }        % does an erasepage
  1459. DEBUG { exec false } { .internalstopped } ifelse {
  1460.   (**** Unable to open the initial device, quitting.) = 1 .quit
  1461. } if
  1462.  
  1463. % If the media size is fixed, update the current page device dictionary.
  1464. FIXEDMEDIA
  1465. dup { pop systemdict /.currentpagedevice known } if
  1466. dup { pop .currentpagedevice exch pop } if
  1467. not { (%END MEDIA) .skipeof } if
  1468. currentpagedevice dup length dict .copydict
  1469. dup /Policies
  1470.     % Stack: <pagedevice> <pagedevice> /Policies
  1471. 1 index /InputAttributes
  1472. 2 copy get dup length dict .copydict
  1473.     % Stack: <pagedevice> <pagedevice> /Policies <pagedevice>
  1474.     %   /InputAttributes <inputattrs'>
  1475. dup 0 2 copy get dup length dict .copydict
  1476.     % Stack: <pagedevice> <pagedevice> /Policies <pagedevice>
  1477.     %   /InputAttributes <inputattrs'> <inputattrs'> 0 <attrs0'>
  1478. dup /PageSize 7 index /PageSize get
  1479. put                % PageSize in 0
  1480. put                % 0 in InputAttributes
  1481. put                % InputAttributes in pagedevice
  1482. % Also change the page size policy so we don't get an error.
  1483.     % Stack: <pagedevice> <pagedevice> /Policies
  1484. 2 copy get dup length dict .copydict
  1485.     % Stack: <pagedevice> <pagedevice> /Policies <policies'>
  1486. dup /PageSize 7 put        % PageSize in Policies
  1487. put                % Policies in pagedevice
  1488. .setpagedevice
  1489. %END MEDIA
  1490. %END DISPLAYING
  1491.  
  1492. (END DEVICE) VMDEBUG
  1493.  
  1494. % Establish a default upper limit in the character cache,
  1495. % namely, enough room for a 18-point character at the resolution
  1496. % of the default device, or for a character consuming 1% of the
  1497. % maximum cache size, whichever is larger.
  1498. mark
  1499.     % Compute limit based on character size.
  1500.   18 dup dtransform
  1501.   exch abs cvi 31 add 32 idiv 4 mul    % X raster
  1502.   exch abs cvi mul        % Y
  1503.     % Compute limit based on allocated space.
  1504.   cachestatus pop pop pop pop pop exch pop 0.01 mul cvi
  1505.   .max dup 10 idiv exch
  1506. setcacheparams
  1507. % Conditionally disable the character cache.
  1508. NOCACHE { 0 setcachelimit } if
  1509.  
  1510. (END CONFIG) VMDEBUG
  1511.  
  1512. % Initialize graphics.
  1513.  
  1514. .setdefaultscreen
  1515. initgraphics
  1516.  
  1517. % The interpreter relies on there being at least 2 entries
  1518. % on the graphics stack.  Establish the second one now.
  1519. gsave
  1520.  
  1521. % Define some control sequences as no-ops.
  1522. % This is a hack to get around problems
  1523. % in some common PostScript-generating applications.
  1524. <04> cvn { } def        % Apple job separator
  1525. <0404> cvn { } def        % two of the same
  1526. <1b> cvn { } def        % MS Windows LaserJet 4 prologue
  1527.                 % (UEL = ESC %-12345X)
  1528. <1b45> cvn { } def        % PJL reset prologue (ESC E)
  1529. <1b451b> cvn { } def        % PJL reset epilogue (ESC E + UEL)
  1530. <041b> cvn { } def        % MS Windows LaserJet 4 epilogue (^D + UEL)
  1531. (\001M) cvn            % TBCP initiator
  1532.  { currentfile /TBCPDecode filter cvx exec
  1533.  } bind def
  1534. /@PJL                % H-P job control
  1535.  { currentfile //=string readline { pop } if
  1536.  } bind def
  1537.  
  1538. % If we want a "safer" system, disable some obvious ways to cause havoc.
  1539. SAFER not { (%END SAFER) .skipeof } if
  1540.  
  1541. .currentglobal true .setglobal
  1542. /SAFETY 2 dict
  1543.   dup /safe DELAYSAFER not put
  1544.   dup /tempfiles 10 dict put
  1545. readonly def
  1546. .setglobal
  1547.  
  1548. /.setsafe
  1549.   { //SAFETY /safe //true .forceput % overrides readonly
  1550.   } .bind executeonly odef
  1551.  
  1552. /file
  1553.  { //SAFETY /safe get {
  1554.      dup (r) eq 2 index (%pipe*) .stringmatch not and
  1555.      2 index (%std*) .stringmatch or
  1556.        { file }
  1557.        { /invalidfileaccess //signalerror exec }
  1558.      ifelse
  1559.    } {
  1560.      file
  1561.    } ifelse
  1562.  } .bind executeonly odef
  1563.  
  1564. /renamefile
  1565.   { //SAFETY /safe get
  1566.       { /invalidfileaccess //signalerror exec }
  1567.       { renamefile }
  1568.     ifelse
  1569.   } .bind executeonly odef
  1570.  
  1571.  
  1572. /deletefile {
  1573.   //SAFETY /safe get {
  1574.     % Allow deleting temporary files (created/opened with .tempfile).
  1575.       //SAFETY /tempfiles get 1 index known {
  1576.     deletefile
  1577.       } {
  1578.     /invalidfileaccess //signalerror exec
  1579.       } ifelse
  1580.     } {
  1581.       deletefile
  1582.   } ifelse
  1583. } .bind executeonly odef
  1584.  
  1585. /putdeviceprops
  1586.  { //SAFETY /safe get { 
  1587.      counttomark
  1588.      dup 2 mod 0 eq { pop /rangecheck //signalerror exec } if
  1589.      3 2 3 2 roll
  1590.       { dup index /OutputFile eq  
  1591.          { -2 roll 
  1592.            dup () ne
  1593.              { /putdeviceprops load /invalidfileaccess //signalerror exec
  1594.              } if
  1595.          3 -1 roll
  1596.          }
  1597.          { pop
  1598.          }
  1599.         ifelse
  1600.       } for
  1601.      putdeviceprops
  1602.    } {
  1603.      putdeviceprops
  1604.    } ifelse
  1605.  } .bind executeonly odef
  1606.  
  1607. % If a file is opened with .tempfile with SAFER not (yet) set,
  1608. % the file can be deleted later, even if SAFER is set.
  1609. /.tempfile {
  1610.   .tempfile    % filename file
  1611.   //SAFETY /safe get not {    % DELAYSAFER, no .setsafe yet
  1612.     //SAFETY /tempfiles get 2 index true put
  1613.   } if
  1614. } .bind executeonly odef
  1615.  
  1616. currentdict /SAFETY undef
  1617.  
  1618. %END SAFER
  1619.  
  1620. % If we delayed binding, make it possible to do it later.
  1621. /.bindnow {
  1622.   //systemdict begin .bindoperators end
  1623.   % Temporarily disable the typecheck error.
  1624.   errordict /typecheck 2 copy get
  1625.   errordict /typecheck { pop } put    % pop the command
  1626.   0 1 .delaycount 1 sub { .delaybind exch get .bind pop } for
  1627.   //systemdict /.delaybind {} .forceput    % reclaim the space
  1628.   //systemdict /.bindnow .forceundef    % ditto
  1629.   put
  1630.   //systemdict /.forcedef .forceundef        % remove temptation
  1631.   //systemdict /.forceput .forceundef        % ditto
  1632.   //systemdict /.forceundef .forceundef        % ditto
  1633. } .bind odef
  1634.  
  1635. % Turn off array packing, since some PostScript code assumes that
  1636. % procedures are writable.
  1637. false setpacking
  1638.  
  1639. (END INIT) VMDEBUG
  1640.  
  1641. /.currentuserparams where {
  1642.   pop
  1643.     % Remove real user params from psuserparams.
  1644.   mark .currentuserparams counttomark 2 idiv {
  1645.     pop psuserparams exch undef
  1646.   } repeat pop
  1647.     % Update the copy of the user parameters.
  1648.   mark .currentuserparams counttomark 2 idiv {
  1649.     userparams 3 1 roll .forceput    % userparams is read-only
  1650.   } repeat pop
  1651.     % Turn on idiom recognition, if available.
  1652.   currentuserparams /IdiomRecognition known {
  1653.     /IdiomRecognition true .definepsuserparam
  1654.   } if
  1655.   psuserparams readonly pop
  1656.   systemdict /.definepsuserparam undef
  1657.     % Save a copy of userparams for use with save/restore
  1658.     % (and, if implemented, context switching).
  1659.   .currentglobal false .setglobal
  1660.      mark userparams { } forall .dicttomark readonly
  1661.      /userparams exch .forcedef        % systemdict is read-only
  1662.   .setglobal
  1663. } if
  1664. /.currentsystemparams where {
  1665.   pop
  1666.     % Remove real system params from pssystemparams.
  1667.   mark .currentsystemparams counttomark 2 idiv {
  1668.     pop pssystemparams exch .forceundef
  1669.   } repeat pop
  1670. } if
  1671.  
  1672. % Conditionally turn image interpolation on or off.
  1673. currentdict /INTERPOLATE known not { (%END INTERPOLATE) .skipeof } if
  1674.  
  1675. /.interpolate {
  1676.   dup /Interpolate .knownget not { //false } if
  1677.   /INTERPOLATE .systemvar ne {
  1678.     dup gcheck .currentglobal exch .setglobal
  1679.     exch dup length dict copy
  1680.     dup /Interpolate /INTERPOLATE .systemvar put
  1681.     exch .setglobal
  1682.   } if
  1683. } bind odef
  1684.  
  1685. /colorimage
  1686.   { /INTERPOLATE .systemvar
  1687.       { .currentglobal                    % w h bit [] {}...{} multi ncomp glob
  1688.         //false .setglobal
  1689.         9 dict begin                      % w h bit [] {}...{} multi ncomp glob
  1690.         2 index { 1 index 7 add } { 8 } ifelse
  1691.         copy gsave pop                    % preserve the arguments
  1692.         { 0 /DeviceGray 0 /DeviceRGB /DeviceCMYK }
  1693.         1 index get setcolorspace         % ... glob w h bit [] {}...{} multi ncomp
  1694.         {0 1 0 1 0 1 0 1}
  1695.         1 index 2 mul 0 exch              % ... glob w h bit [] {}...{} multi ncomp {0 1 ...} 0 2*ncomp
  1696.         getinterval /Decode exch def      % ... glob w h bit [] {}...{} multi ncomp
  1697.         exch dup                          % ... glob w h bit [] {}...{} ncomp multi multi
  1698.         /MultipleDataSources exch def     % ... glob w h bit [] {}...{} ncomp multi
  1699.         { array astore} { pop } ifelse    % ... glob w h bit [] [{}...{}]
  1700.         /DataSource exch def              % ... glob w h bit []
  1701.         /ImageMatrix exch def             % ... glob w h bit
  1702.         /BitsPerComponent exch def        % ... glob w h
  1703.         /Height exch def                  % ... glob w
  1704.         /Width exch def                   % ... glob 
  1705.         /ImageType 1 def
  1706.         /Interpolate //true def
  1707.         .setglobal currentdict end        % ... <<>>
  1708.         image grestore
  1709.         exch { 4 add } { 6 } ifelse
  1710.         { pop } repeat                    % -
  1711.       }
  1712.       { colorimage
  1713.       }
  1714.     ifelse
  1715.   } bind odef
  1716.  
  1717. /image
  1718.   { dup type /dicttype eq
  1719.       { dup /ImageType get 3 eq
  1720.           { .currentglobal //false .setglobal exch
  1721.             dup length dict copy begin .setglobal 
  1722.             /DataDict DataDict .interpolate def
  1723.             /MaskDict MaskDict .interpolate def
  1724.             currentdict end
  1725.           }
  1726.           { .interpolate 
  1727.           }
  1728.         ifelse
  1729.         image
  1730.       }
  1731.       { /INTERPOLATE .systemvar
  1732.           { .currentglobal //false .setglobal
  1733.             8 dict begin .setglobal
  1734.             /ImageType 1 def
  1735.             /DataSource 1 index def
  1736.             /ImageMatrix 2 index def
  1737.             /BitsPerComponent 3 index def
  1738.             /Decode {0 1} def
  1739.             /Height 4 index def
  1740.             /Width 5 index def
  1741.             /Interpolate //true def
  1742.             currentdict end
  1743.             gsave /DeviceGray setcolorspace image grestore
  1744.             5 { pop } repeat
  1745.           }
  1746.           { image
  1747.           }
  1748.         ifelse
  1749.       }
  1750.     ifelse
  1751.   } bind odef
  1752.  
  1753. /imagemask {
  1754.   dup type /dicttype eq {
  1755.     .interpolate imagemask
  1756.   } {
  1757.     /INTERPOLATE .systemvar {
  1758.       .currentglobal //false .setglobal
  1759.       8 dict begin .setglobal
  1760.       /ImageType 1 def
  1761.       /DataSource 1 index def
  1762.       /ImageMatrix 2 index def
  1763.       /BitsPerComponent 1 def
  1764.       2 index { {1 0} } { {0 1} } ifelse /Decode exch def
  1765.       /Height 4 index def
  1766.       /Width 5 index def
  1767.       /Interpolate //true def
  1768.       currentdict end imagemask 5 { pop } repeat
  1769.     } {
  1770.       imagemask
  1771.     } ifelse
  1772.   } ifelse
  1773. } bind odef
  1774.  
  1775. currentdict /.interpolate undef
  1776.  
  1777. %END INTERPOLATE
  1778.  
  1779. % Establish local VM as the default.
  1780. false /setglobal where { pop setglobal } { .setglobal } ifelse
  1781. $error /.nosetlocal false put
  1782.  
  1783. (END GLOBAL) VMDEBUG
  1784.  
  1785. /.savelocalstate where {
  1786.     % If we might create new contexts, save away copies of all dictionaries
  1787.     % referenced from systemdict that are stored in local VM,
  1788.     % and also save a copy of the initial gstate.
  1789.   pop .savelocalstate
  1790. } {
  1791.     % If we're *not* running in a multi-context system and FAKEFONTS is
  1792.     % defined, add the fake fonts to LocalFontDirectory.
  1793.   .definefakefonts    % current VM is local
  1794. } ifelse
  1795.  
  1796. % Remove systemdict entries for things that have been bound in where used
  1797. % and that shouldn't be accessible by name, and close up systemdict.
  1798. currentdict /filterdict .undef
  1799. currentdict /.cidfonttypes .undef
  1800. currentdict /.colorrenderingtypes .undef
  1801. currentdict /.formtypes .undef
  1802. currentdict /.halftonetypes .undef
  1803. currentdict /.imagetypes .undef
  1804. currentdict /.imagemasktypes .undef
  1805. currentdict /.patterntypes .undef
  1806. currentdict /.shadingtypes .undef
  1807. currentdict /.wheredict .undef
  1808. end
  1809.  
  1810. % Clean up VM, and enable GC.
  1811. /vmreclaim where
  1812.  { pop NOGC not { 2 vmreclaim 0 vmreclaim } if
  1813.  } if
  1814. DELAYBIND not {
  1815.   systemdict /.forcedef .undef        % remove temptation
  1816.   systemdict /.forceput .undef        % ditto
  1817.   systemdict /.forceundef .undef    % ditto
  1818. } if
  1819. WRITESYSTEMDICT not { systemdict readonly pop } if
  1820.  
  1821. (END GC) VMDEBUG
  1822.  
  1823. % The Adobe AGM_Core used by Illustrator 9 has some code that breaks
  1824. % if the 'product' is not (Adobe PostScript Parser). A bug has been
  1825. % submitted to Adobe since this also fails with Acrobat Distiller.
  1826. % As a temporary work around, the following HACK will work for
  1827. % devices without spot color support. Once Ghostscript can
  1828. % support DeviceN and spot color separations this will need to
  1829. % be 'true' in some cases.
  1830. userdict /AGM_preserve_spots false put
  1831.  
  1832. % The interpreter will run the initial procedure (start).
  1833.